package com.company.pedidos.repository;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.company.pedidos.domain.Cliente;
import com.company.domain.repository.BaseRepository;

public interface ClienteRepository extends BaseRepository<Cliente, Long> {

	/**
	 * 
	 * @param id
	 * @return
	 */
	Cliente findById(Long id);

	/**
	 * 
	 * @param name
	 * @return
	 */
	Cliente findByCodigo(String name);

	/**
	 * 
	 * @param razonSocial
	 * @return
	 */
	List<Cliente> findByRazonSocial(String razonSocial);

	/**
	 * 
	 * @param pageable
	 * @param tipoDocumento
	 * @param nroDocumento
	 * @return
	 */
	@Query(value = "select x from Cliente x where x.tipoDocumento = :tipoDocumento and x.nroDocumento = :nroDocumento and razonSocial = :razonSocial", 
			countQuery = "select count(x) from Cliente x where x.tipoDocumento = :tipoDocumento and x.nroDocumento = :nroDocumento and razonSocial = :razonSocial")
	Page<Cliente> findByTipoDocumentoAndNroDocumento(
			@Param("tipoDocumento") String tipoDocumento,
			@Param("nroDocumento") String nroDocumento,
			@Param("razonSocial") String razonSocial, Pageable pageable);
}
